package com.hackintosh.state.thread;

/**
 * @description：运行状态
 * @author：twislyn
 * @date：Created in 2021/05/23
 * @modified By：
 * @version: 1.0
 */
public class Running extends AbstractThreadState {

    public Running() {
        this.stateName = "RUNNING";
        System.out.println("当前线程处于：运行状态.");
    }

    /**
     * 暂停
     *
     * @param threadContext
     */
    public void suspend(ThreadContext threadContext) {
        System.out.print("调用suspend()方法-->");
        if (stateName.equals("RUNNING")) {
            threadContext.setState(new Blocked());
        } else {
            System.out.println("当前线程不是运行状态，不能调用suspend()方法.");
        }
    }

    /**
     * 停止
     *
     * @param threadContext
     */
    public void stop(ThreadContext threadContext) {
        System.out.print("调用stop()方法-->");
        if (stateName.equals("RUNNING")) {
            threadContext.setState(new Dead());
        } else {
            System.out.println("当前线程不是运行状态，不能调用stop()方法.");
        }
    }
}
